﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace OpenSln
{
    public partial class Form1 : Form
    {
        public Thread th;
        public int count = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            count = 0;
            Common.savePath(this.textBox1.Text);
            Common.saveSecond(this.textBox2.Text);
            th = new Thread(new ThreadStart(OpenSln));
            th.Start();

            
            //Process.Start("E:/aaa/web/ErQi2.0/ErQi2.0.sln");
        }
        public void OpenSln()
        {
            var folds = Directory.GetDirectories(this.textBox1.Text);
            foreach (string fold in folds)
            {
                if (fold.Contains("2.0"))
                {
                    var files = Directory.GetFiles(fold);
                    foreach (string file in files)
                    {
                        if (file.Contains(".sln"))
                        {
                            count++;
                            Process.Start(file);
                            this.label3.Text = count.ToString();
                            Thread.Sleep(int.Parse(this.textBox2.Text)*1000);
                        }
                    }
                }
            }
            th.Abort();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            this.textBox1.Text = Common.GetConfig("Path");
            this.textBox2.Text = Common.GetConfig("Second");
        }
    }
}
